home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / sound / misc / muispeak.lha / MuiSpeak / src / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-07  |  6.9 KB  |  325 lines

  1. #include <intuition/intuition.h>
  2.  
  3. #include <libraries/mui.h>
  4. #include <libraries/locale.h>
  5. #include <libraries/gadtools.h>
  6.  
  7.  
  8. #include <clib/locale_protos.h>
  9. #include <clib/muimaster_protos.h>
  10. #include <clib/alib_protos.h>
  11. #include <clib/dos_protos.h>
  12. #include <clib/exec_protos.h>
  13. #include <devices/narrator.h>
  14.  
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17.  
  18. #include "speak.h"
  19.  
  20.  
  21. #define CATCOMP_BLOCK
  22. #include "speakstrings_cat.h"
  23.  
  24. #undef CATCOMP_BLOCK
  25.  
  26. #define DEFAULT_STR        "Hello. This is Amiga speaking."
  27.  
  28. BYTE audio_chn[3][4] ={ {1,8,0,0},  {2,4,0,0}, {3,5,10,12} };
  29.  
  30.  
  31. struct LocaleBase *     LocaleBase;
  32. struct Library *         MUIMasterBase;
  33. struct MsgPort *        SpeakMP;
  34.  
  35. struct Locale *            locale = NULL;
  36. struct Catalog *        Catalog = NULL;
  37.  
  38. struct narrator_rb *     SpeakIO;
  39. struct ObjApp *         App    = NULL;
  40.  
  41. int PITCH    = 120;
  42. int SPEED    = 120;
  43. int VOLUME    = 64;
  44. int SEX        = MALE;
  45. int KIND    = ROBOTICF0;
  46. int ENTHU   = 0;
  47. int PERTUB  = 0;
  48. int OUTPUT_CHANNEL =2;
  49. int F1ADJ    = 0;
  50. int F2ADJ    = 0;
  51. int F3ADJ    = 0;
  52. int A1ADJ    = 0;
  53. int A2ADJ    = 0;
  54. int A3ADJ    = 0;
  55. int ARTIC    = 0;
  56. int AVBIAS    = 0;
  57. int AFBIAS    = 0;
  58. int CENT    = 0;
  59.  
  60. /****************************************************************/
  61.  
  62. void main(int argc,char **argv);
  63.  
  64. /****************************************************************/
  65.  
  66. int wbmain(struct WBStartup *wb_startup)
  67. {
  68.  
  69.     main(0, NULL);
  70. }
  71.  
  72.  
  73. /****************************************************************/
  74.  
  75. char * MyTranslate(char * str)
  76. {
  77.     char ph_buf[255];
  78.  
  79.     Translate(str , strlen(str) , (APTR) ph_buf , 255);
  80.         
  81.     return ph_buf;
  82. }
  83.  
  84. /****************************************************************/
  85.  
  86. void Speak(char *str)
  87. {
  88.     static char ph_buf[255];
  89.  
  90.     Translate(str , strlen(str) , (APTR) ph_buf , 255);
  91.  
  92.     set( App->TX_PHONEME , MUIA_Text_Contents,ph_buf);
  93.  
  94.     set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  95.  
  96.  
  97.     SpeakIO->message.io_Command    = CMD_WRITE;
  98.     SpeakIO->message.io_Offset    = 0;
  99.     SpeakIO->message.io_Data    = ph_buf;
  100.     SpeakIO->message.io_Length    = strlen( ph_buf );
  101.  
  102.     SpeakIO->ch_masks            = audio_chn[OUTPUT_CHANNEL];
  103.     SpeakIO->nm_masks            = sizeof(audio_chn)/3;
  104.     SpeakIO->rate                = SPEED;
  105.     SpeakIO->pitch                = PITCH;
  106.     SpeakIO->volume                = VOLUME;
  107.     SpeakIO->sex                = SEX;
  108.     SpeakIO->mode                = KIND;
  109.     SpeakIO->F0enthusiasm        = ENTHU;
  110.     SpeakIO->F0perturb            = PERTUB;
  111.  
  112.     SpeakIO->F1adj                = F1ADJ;
  113.     SpeakIO->F1adj                = F2ADJ;
  114.     SpeakIO->F1adj                = F3ADJ;
  115.     SpeakIO->A1adj                = A1ADJ;
  116.     SpeakIO->A2adj                = A2ADJ;
  117.     SpeakIO->A3adj                = A3ADJ;
  118.     SpeakIO->articulate            = ARTIC;
  119.     SpeakIO->AVbias                = AVBIAS;
  120.     SpeakIO->AFbias                = AFBIAS;
  121.     SpeakIO->centralize            = CENT;
  122.     
  123.     DoIO((struct IORequest *) SpeakIO);
  124. }
  125.  
  126. /****************************************************************/
  127.  
  128. void init(void)
  129. {
  130.     if (!(MUIMasterBase =  OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  131.     {
  132.         printf("Can't open muimaster.library V %d+\n",MUIMASTER_VMIN);
  133.         exit(0);
  134.     }
  135.     
  136.     SpeakMP = CreateMsgPort();
  137.     SpeakIO = (struct narrator_rb *) CreateExtIO(SpeakMP,sizeof(struct narrator_rb));
  138.     SpeakIO->flags = NDF_NEWIORB;
  139.                 
  140.     OpenDevice("narrator.device",0,(struct IORequest *) SpeakIO,NULL);
  141. }
  142.  
  143. /****************************************************************/
  144.  
  145. void main(int argc,char **argv)
  146. {
  147.     BOOL    running = TRUE;
  148.     ULONG    signal;
  149.     int i;
  150.  
  151.     LocaleBase = (struct LocaleBase *) OpenLibrary("locale.library",37);
  152.  
  153.     if (LocaleBase != NULL)
  154.     {
  155.         struct TagItem tags[3];
  156.     
  157.         locale = OpenLocale(NULL);
  158.  
  159.         if (strcmp(locale->loc_LanguageName,"deutsch.language"))   // Builtin language != locale Language
  160.         {
  161.             tags[0].ti_Tag  = OC_BuiltInLanguage;
  162.             tags[0].ti_Data = (ULONG) "deutsch";    
  163.  
  164.             tags[1].ti_Tag  = OC_Version;
  165.             tags[1].ti_Data = (ULONG) 1;
  166.  
  167.             tags[2].ti_Tag  = OC_BuiltInCodeSet;    // Default, requested from Commodore
  168.             tags[2].ti_Data = (ULONG) 0;
  169.  
  170.             Catalog=OpenCatalogA(NULL,"muispeak.catalog",tags);
  171.  
  172.          }
  173.     }    
  174.  
  175.     init();
  176.  
  177.     App = CreateApp();
  178.  
  179.     get(App->CY_SEX,MUIA_Cycle_Active,&SEX);
  180.     get(App->CY_KIND,MUIA_Cycle_Active,&KIND);
  181.     get(App->SL_SPEED,MUIA_Slider_Level,&SPEED);
  182.     get(App->SL_HEIGHT,MUIA_Slider_Level,&PITCH);
  183.     get(App->SL_VOLUME,MUIA_Slider_Level,&VOLUME);
  184.     get(App->SL_PERTUBATION,MUIA_Slider_Level,&PERTUB);
  185.     get(App->SL_ENTHUSIASMUS,MUIA_Slider_Level,&ENTHU);
  186.  
  187.     set(App->CY_OUTPUT,MUIA_Cycle_Active,&OUTPUT_CHANNEL);
  188.  
  189.     
  190.     setstring( App->STR_TEXT , DEFAULT_STR);
  191.     set( App->TX_PHONEME , MUIA_Text_Contents,MyTranslate(DEFAULT_STR));
  192.  
  193.  
  194.     while (running)
  195.     {
  196.         switch (DoMethod(App->App,MUIM_Application_Input,&signal))    
  197.         {
  198.             case RET_SPEAK:
  199.                 char *x;
  200.                 get(App->STR_TEXT,MUIA_String_Contents,&x);
  201.                 Speak(x);
  202.                 break;
  203.  
  204.             case RET_SEX:
  205.                 get(App->CY_SEX,MUIA_Cycle_Active,&SEX);
  206.                 break;
  207.  
  208.             case RET_KIND:
  209.                 get(App->CY_KIND,MUIA_Cycle_Active,&KIND);
  210.                 break;
  211.  
  212.             case RET_OUTPUT:
  213.                 get(App->CY_OUTPUT,MUIA_Cycle_Active,&OUTPUT_CHANNEL);
  214.                 break;
  215.  
  216.             case RET_SPEED:
  217.                 get(App->SL_SPEED,MUIA_Slider_Level,&SPEED);
  218.                 break;
  219.  
  220.             case RET_HEIGHT:
  221.                 get(App->SL_HEIGHT,MUIA_Slider_Level,&PITCH);
  222.                 break;
  223.  
  224.             case RET_VOLUME:
  225.                 get(App->SL_VOLUME,MUIA_Slider_Level,&VOLUME);
  226.                 break;
  227.  
  228.             case RET_PERTUB:
  229.                 get(App->SL_PERTUBATION,MUIA_Slider_Level,&PERTUB);
  230.                 break;
  231.  
  232.             case RET_ENTHU:
  233.                 get(App->SL_ENTHUSIASMUS,MUIA_Slider_Level,&ENTHU);
  234.                 break;
  235.             
  236.             case RET_F1ADJ:
  237.                 get(App->SL_F1ADJ,MUIA_Slider_Level,&F1ADJ );
  238.                 break;    
  239.  
  240.             case RET_F2ADJ:
  241.                 get(App->SL_F2ADJ,MUIA_Slider_Level,&F2ADJ );
  242.                 break;    
  243.  
  244.             case RET_F3ADJ:
  245.                 get(App->SL_F3ADJ,MUIA_Slider_Level,&F3ADJ );
  246.                 break;    
  247.  
  248.             case RET_A1ADJ:
  249.                 get(App->SL_A1ADJ,MUIA_Slider_Level,&A1ADJ );
  250.                 break;    
  251.  
  252.             case RET_A2ADJ:
  253.                 get(App->SL_A2ADJ,MUIA_Slider_Level,&A2ADJ );
  254.                 break;    
  255.  
  256.             case RET_A3ADJ:
  257.                 get(App->SL_A3ADJ,MUIA_Slider_Level,&A3ADJ );
  258.                 break;    
  259.  
  260.             case RET_AFBIAS:
  261.                 get(App->SL_AFBIAS,MUIA_Slider_Level,&AFBIAS);
  262.                 break;    
  263.  
  264.             case RET_AVBIAS:
  265.                 get(App->SL_AVBIAS,MUIA_Slider_Level,&AVBIAS);
  266.                 break;    
  267.  
  268.             case RET_ARTIC:
  269.                 get(App->SL_ARTIC,MUIA_Slider_Level,&ARTIC);
  270.                 break;    
  271.  
  272.             case RET_CENT:
  273.                 get(App->SL_CENT,MUIA_Slider_Level,&CENT);
  274.                 break;    
  275.  
  276.             case RET_TEXT:
  277.                 char *x;
  278.                 get(App->STR_TEXT,MUIA_String_Contents,&x);
  279.                 set( App->TX_PHONEME , MUIA_Text_Contents, MyTranslate(x));
  280.                 set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  281.                 break;
  282.  
  283.             case MUIV_Application_ReturnID_Quit:
  284.                 running = FALSE;
  285.                         break;
  286.         }
  287.  
  288.         if (running && signal) Wait(signal);
  289.  
  290.     }        
  291.  
  292.     
  293.  
  294.     CloseDevice((struct IORequest *) SpeakIO);
  295.     DeleteIORequest((struct IORequest *) SpeakIO);
  296.     DeleteMsgPort(SpeakMP);
  297.  
  298.     DisposeApp(App);
  299.     CloseLibrary(MUIMasterBase);
  300.     CloseLibrary((struct Library *) LocaleBase);
  301. }
  302.  
  303.  
  304. char * GetString(int stringNum)
  305. {
  306.     LONG   *l;
  307.     UWORD  *w;
  308.     STRPTR  builtIn;
  309.  
  310.     l = (LONG *)CatCompBlock;
  311.  
  312.     while (*l != stringNum)
  313.     {
  314.         w = (UWORD *)((ULONG)l + 4);
  315.         l = (LONG *)((ULONG)l + (ULONG)*w + 6);
  316.     }
  317.     builtIn = (STRPTR)((ULONG)l + 6);
  318.  
  319.  
  320.     if (LocaleBase)
  321.         return(GetCatalogStr(Catalog,stringNum,builtIn));
  322.  
  323.     return(builtIn);}
  324.  
  325.